import os
import shutil

def replace_name(target_folder, replacement_chars):
    # target_folder = "/path/to/your/folder"
    # replacement_chars = "XYZ"

    for filename in os.listdir(target_folder):
        if os.path.isfile(os.path.join(target_folder, filename)):
            old_filepath = os.path.join(target_folder, filename)
            new_filename = replacement_chars + filename[3:]
            new_filepath = os.path.join(target_folder, new_filename)

            os.rename(old_filepath, new_filepath)

if __name__ == '__main__':
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/bluegrass/images", "bluegrass")
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/bluegrass/label", "bluegrass")

    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/chenopodium album/images", "chenopodium")
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/chenopodium album/label", "chenopodium")

    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/cirsium setosum/images", "cirsium")
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/cirsium setosum/label", "cirsium")

    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/corn/images", "corn")
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/corn/label", "corn")

    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/sedge/images", "sedge")
    replace_name("C:/Users/64531/Desktop/weed-datasets/allcorn weed datasets/sedge/label", "sedge")